//好友页面
Cn_Friend ={
	init : function(){
		if(!Jes.userSess(1)) return;//session
		var type = Jes.request('type') || 1;
		this.query(type);
	}
	//1.互相关注   2.我关注的  
	,query : function(type){
		for(var i=1;i<4;i++){
			if(i!=type) {
				$('#tab1'+i).removeClass('tabseled');
			}
		}
		$('#tab1'+type).addClass('tabseled');
		Jes.doQueryList('cnfriend_query_sql@idx',{paraObj:"{type:"+type+"}",isLoad:false},function(data){
			var html=[],tsgzinfo;
			for(var i=0;i<data.length;i++){
				var remark ='添加备注';
				if(data[i].remark!=null&&!data[i].remark==''){
					remark=data[i].remark;
				}
				if(data[i].isgz=='1'){
					html.push('	<li class="MIB_linedot_l downline" onmouseover="showhid(\'downmenu'+i+'\');showhid(\'moreinfo'+i+'\')" onmouseout="showhid2(\'downmenu'+i+'\');showhid2(\'moreinfo'+i+'\')">');
				}else{
					html.push('	<li class="MIB_linedot_l downline" onmouseover="showhid(\'downmenu'+i+'\');" onmouseout="showhid2(\'downmenu'+i+'\');">');
				}
				html.push('<div class="user_pic user_Stat"> <div class="head_pic" >');
				if(data[i].usertype=='2'){//认证商家
					html.push('<a href="./indexbus.html?uid='+data[i].fuserid+'" class="add_pic" title="'+ data[i].loginid +'"><img style="width:50px;height:50px;border:2px solid #155FBE;"  src="'+ Jes.getPicPath(data[i].pic) +'" title="'+ data[i].loginid +'" class="picborder_l"/></a>');
				}
				if(data[i].usertype=='0'){//商家
					html.push('<a href="./indexbus.html?uid='+data[i].fuserid+'" class="add_pic" title="'+ data[i].loginid +'"><img style="width:50px;height:50px;border:1px solid #155FBE;"  src="'+ Jes.getPicPath(data[i].pic) +'" title="'+ data[i].loginid +'" class="picborder_l"/></a>');
				}
				if(data[i].usertype!='0'&&data[i].usertype!='2'){//非商家
					html.push('<a href="./person.html?uid='+data[i].fuserid+'" class="add_pic" title="'+ data[i].loginid +'"><img style="width:50px;height:50px;"  src="'+ Jes.getPicPath(data[i].pic) +'" title="'+ data[i].loginid +'" class="picborder_l"/></a>');
				}
				html.push('</div></div><div class="MIB_feed_c"><div id="downmenu'+i+'" class="gz_prompt" style="display:none;" >');
                if(data[i].isgz=='1'){
                	html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.qxgzshow(\'#hidegz1\',\''+data[i].fuserid+'\')" style="color:#ED1B24">取消关注</a></p>');
                	if(data[i].ishxgz=='1'){
                		html.push('<p style="color:#787878;">已互相关注</p>');
                		html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.fasxshow(\'#showDiv2\',\''+data[i].fuserid+'\')" style="color:#ED1B24">发送私信</a></p>');
                	}else{
                		html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.qgzshow(\'#hidegz2\',\''+data[i].fuserid+'\')" style="color:#ED1B24">求关注</a></p>');
                	}
                }else{
                	html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.doGuanzhu(\''+data[i].fuserid+'\',\''+data[i].loginid+'\')" style="color:#ED1B24">加关注</a></p>');
                }
             	if(data[i].name=='特别关注'){
					tsgzinfo = '<a href="javascript:Comm.doTsgz(\'tsgz'+data[i].fuserid+'\',\''+data[i].fuserid+'\');" title="取消特别关注" id="tsgz'+data[i].fuserid+'" class="tsgz" ></a>';
				}else{
					tsgzinfo = '<a href="javascript:Comm.doTsgz(\'tsgz'+data[i].fuserid+'\',\''+data[i].fuserid+'\');" title="添加到特别关注" id="tsgz'+data[i].fuserid+'"  class="notsgz"></a>';
				}
				if(data[i].usertype=='2'){//认证商家
					html.push('</div><p><a href="./indexbus.html?uid='+data[i].fuserid+'" title="认证商家" style="color:blue" class="blue14 vip" >'+ data[i].loginid +'</a>(<a href="javascript:void(1);" onclick="Cn_Index.showDiv(\'#showDiv5\',\'fuserid\',\''+data[i].fuserid+'\')"  style="color:blue">'+remark+'</a>)'+tsgzinfo+'</p><div class="gz_con" >');
				}
				if(data[i].usertype=='0'){//商家
					html.push('</div><p><a href="./indexbus.html?uid='+data[i].fuserid+'" title="商家" style="color:blue">'+ data[i].loginid +'</a>(<a href="javascript:void(1);" onclick="Cn_Index.showDiv(\'#showDiv5\',\'fuserid\',\''+data[i].fuserid+'\')"  style="color:blue">'+remark+'</a>)'+tsgzinfo+'</p><div class="gz_con" >');
				}
				if(data[i].usertype!='0'&&data[i].usertype!='2'){//非商家
					html.push('</div><p><a href="./person.html?uid='+data[i].fuserid+'">'+ data[i].loginid +'</a>(<a href="#" onclick="Cn_Index.showDiv(\'#showDiv5\',\'fuserid\',\''+data[i].fuserid+'\')"  style="color:#ED1B24">'+remark+'</a>)'+tsgzinfo+'</p><div class="gz_con" >');
				}
                if(data[i].isgz=='1'){
                	html.push('<div id="moreinfo'+i+'" style="display:none;"><a href="#" class="gz_wfz" onclick="Cn_Friend.initGroup(\''+data[i].fuserid+'\',\''+userInfo.userid+'\')"><span></span></a></div>');
                }
                //html.push('<p class="gz_js" >职业: '+data[i].job+'</p><p class="gz_js">'+data[i].area+' | '+data[i].city+' </p>');
                html.push('<p class="gz_js" >关注 '+data[i].follownum+' | 被关注'+data[i].fansnum+' | 活动'+data[i].reqnum+'</p><p class="gz_js" >简介： '+data[i].sign+ ' </p>');
                html.push('</div></div><div class="clear"></div></li>');
			}
			Jes.html('msg_list',html);
		});
	}
	//好友html
	,_friendHtml : function(data,type){
		html.push('	<li class="MIB_linedot_l downline" onmouseover="showhid(\'downmenu'+i+'\');showhid(\'moreinfo'+i+'\')" onmouseout="showhid2(\'downmenu'+i+'\');showhid2(\'moreinfo'+i+'\')">');
		html.push(' <div class="user_pic user_Stat"> <div class="head_pic" >');
		html.push('<a href="javascript:void(0);" class="add_pic" title="'+ data[i].loginid +'"><img style="width:50px;height:50px;"  src="'+ Jes.getPicPath(data[i].pic) +'" title="'+ data[i].loginid +'" class="picborder_l"/></a>');					
		html.push('</div></div><div class="MIB_feed_c"><div id="downmenu'+i+'" class="gz_prompt" style="display:none;" >');			
        if(type==1){
       		html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.qxgzshow(\'#hidegz1\',\''+data[i].fuserid+'\')" style="color:#ED1B24">取消关注</a></p>');
        	html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.fasxshow(\'#showDiv2\',\''+data[i].fuserid+'\')" style="color:#ED1B24">发送私信</a></p>');
        }
        if(type==2){
            html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.qxgzshow(\'#hidegz1\',\''+data[i].fuserid+'\')" style="color:#ED1B24">取消关注</a></p>');
            html.push('<p><a href="javascript:void(0);" onclick="Cn_Friend.qgzshow(\'#hidegz2\',\''+data[i].fuserid+'\')" style="color:#ED1B24">求关注</a></p>');
        }
		html.push('</div><p><a href="javascript:void(0);">'+ data[i].loginid +'</a>(<a href="#" onclick="Cn_Index.showDiv(\'#showDiv5\')"  style="color:#ED1B24">添加备注</a>)</p><div class="gz_con" id="moreinfo'+i+'" style="display:none;">');
        if(type!=3){
        	html.push('<a href="javascript:void(0);" class="gz_wfz" onclick="Cn_Friend.initGroup(\''+data[i].fuserid+'\',\''+userInfo.userid+'\')">'+data[i].name+'<span></span></a>');
        }
        html.push('<p class="gz_js" >职业: '+data[i].job+'</p><p class="gz_js">'+data[i].area+' | '+data[i].city+' </p>');
        html.push('<p class="gz_js" >关注 '+data[i].follownum+' | 被关注'+data[i].fansnum+' | 活动'+data[i].reqnum+'</p><p class="gz_js" >简介： '+data[i].sign+ ' </p>');
        html.push('</div></div><div class="clear"></div></li>');
		return html;
	}
	,doGuanzhu : function(fuserid, fuserloginid) {
		if(fuserid==userInfo.userid){
			Jes.alert("关注他人总比关注自己更好");
			return;
		}
		Jes.doSaveTObject('cn.guanzhu',{param:{'fuserid':fuserid}},function(data){
            Cn_Index.queryUserInfo();
            Cn_Index.initGroup(fuserid, fuserloginid);
		});
	}
	//取消关注	
	,qxgzshow : function(obj,fuserid){
		//showDiv(obj);
		Cn_Index.showDiv(obj);
		Jes('fuserid').value = fuserid;
	}
	,doRemoveGuanzhu : function(){
		Jes.doSaveTObject('cn.removeguanzhu',{param:{'fuserid':Jes('fuserid').value}},function(data){
			Jes.hide('hidegz1');
			Jes.alert(data);
			Cn_Friend.init();
		});
	}
	,initGroup : function(fuserid, fuserloginid) {
		Jes('fuserid').value = fuserid;
        Jes.doQueryList('cngroup_query_sql@idx',{paraObj:"{userid:'"+ userInfo.userid +"'}",isLoad:false},function(data){
        	var html = [];
            for (var i = 0; i < data.length; i++) {
                html.push('<li><a href="javascript:void(0);"><input type="checkbox" value="' + data[i].id + '">' + data[i].name + '</a></li>')
            }
            Jes.html('fri_option_groups',html);
        });
        Cn_Index.showDiv('#showDiv7');//和右侧的分组有区别
    }
    ,addNewGroup: function() {
        Jes.doSaveTObject('cn.addnewgroup', {param: {groupName: $('#newGroupName').val().trim()}}, function(groupId) {
            if (groupId == "0") {
                Jes.alert("分组已存在");
            } else {
                $('#option_groups').append('<li><a href="javascript:void(0);"><input type="checkbox" value="' + groupId + '">' + $('#newGroupName').val() + '</a></li>');
            }
            $('#newGroupName').val('');
        });
    }
    ,doGroup : function() {
        /*var groupIds = [];
        $('#showDiv4 :checked').val(function(i, val) {
            groupIds.push(val);
        });*/
        var groupIds = $('#showDiv7 :checked').val();
        if(groupIds==null||groupIds==''){
        	groupIds = '1';//默认为 未分组
        }
        Jes.doSaveTObject('cn.savefriendgroup', {param: {fuserid: Jes('fuserid').value, groupIds: groupIds}}, function(data) {
            $('#showDiv7').hide();
            Cn_Friend.init();
        });
    }
    //发送私信
    ,fasxshow : function(obj,fuserid){
		Cn_Index.showDiv(obj);
		Jes('fuserid').value = fuserid;
	}
    //求关注
    ,qgzshow : function(obj,fuserid){
		Cn_Index.showDiv(obj);
		Jes('fuserid').value = fuserid;
	}
	,send : function(type){//私信1  求关注2
		var content = '';
		var fuserid = Jes('fuserid').value;
		if(type=='1'){
			content = Jes('letter_area').value;
		}else{
			content = Jes('qgz_content').value;
		}
		
		if(fuserid==null){Jes.alert("请填写发送对象");return;}
		Jes.save('CnMsg',{param:{'fuserid':fuserid,'content':content}},function(data){
			if(data==1){
				Jes.alert('发送成功');
				Jes.hide('hidegz2');
				Jes.hide('showDiv2');
			}else{
				Jes.alert('发送失败')
			}
		})
	}
}